package com.kacheap.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kacheap.service.RemoteApiService;

@RestController
@RequestMapping("/retry/")
public class RetryController {

	@Autowired
	private RemoteApiService remoteApiService;

	@GetMapping("execute/{num}")
	public String execute(@PathVariable(name = "num", required = true) int num) {
		try {
			boolean success = remoteApiService.pay(num);

			if (success) {
				return "Successful";
			}

			return "failure";
		} catch (Exception e) {
			return "failure";
		}
	}

}
